package org.suren.littlebird.console;

import org.eclipse.jdt.internal.debug.core.JavaDebugUtils;
import org.eclipse.jdt.internal.debug.ui.console.JavaExceptionHyperLink;
import org.eclipse.jdt.internal.debug.ui.console.JavaStackTraceHyperlink;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.ui.console.IHyperlink;
import org.eclipse.ui.console.IPatternMatchListener;
import org.eclipse.ui.console.PatternMatchEvent;
import org.eclipse.ui.console.TextConsole;

/**
 * @author suren
 * @date 2015-4-21
 *
 * http://surenpi.com
 */
public class SuRenPatternMatchListener implements IPatternMatchListener
{
	private TextConsole console;

	@Override
	public void matchFound(PatternMatchEvent event)
	{
	    try
	    {
	      int offset = event.getOffset();
	      int length = event.getLength();
	      IHyperlink link = new JavaStackTraceHyperlink(console);
	      this.console.addHyperlink(link, offset + 1, length - 2);
	    }
	    catch (BadLocationException localBadLocationException)
	    {
	    }
	}

	@Override
	public void disconnect()
	{
		this.console = null;
	}

	@Override
	public void connect(TextConsole console)
	{
		this.console = console;
	}

	@Override
	public String getPattern()
	{
		return "\\([\\d a-z A-z _]+.java:\\d+\\)";
	}

	@Override
	public String getLineQualifier()
	{
		return null;
	}

	@Override
	public int getCompilerFlags()
	{
		return 0;
	}
}
